﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using DAL;
using BUS;

namespace WEBSITE_BANDEAL.Admin
{
    public partial class BaiViet_List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lit_title.Text = "Quản lý bài viết";
            lit_title_header.Text = "Danh sách bài viết";
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            Baivetcollection bv = BAI_VIETBUS.GetAll();
            Repeater1.DataSource = bv;
            Repeater1.DataBind();  
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //Literal lit_ten = (Literal)e.Item.FindControl("lit_ten");
                Literal lit_trangthai = (Literal)e.Item.FindControl("lit_trangthai");
                Literal lit_tencha = (Literal)e.Item.FindControl("lit_tencha");
                Literal lit_noidung = (Literal)e.Item.FindControl("lit_noidung");
                BAI_VIET bv = (BAI_VIET)e.Item.DataItem;
                lit_tencha.Text = LOAI_BAI_VIETBUS.GetCha(bv.Maloaibv);
                lit_noidung.Text = bv.Noidung.ToString();

                if (bv.Trangthai == 1)
                {
                    lit_trangthai.Text = " <img src='../Template/images/admin/check.png' alt='" + bv.Mabv.ToString() + "' onClick='AnHien(" + bv.Mabv + ")' title='Hiện' style='margin:10px;cursor:pointer;'  />";
                }
                else
                {
                    lit_trangthai.Text = "<img src='../Template/images/admin/cancel.png' alt='" + bv.Mabv.ToString() + "' onClick='AnHien(" + bv.Mabv + ")' title='Ẩn' style='margin:10px;cursor:pointer;' />";
                }
            }
        }
    }
}